<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数据重置 - 外卖平台</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Microsoft YaHei', Arial, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 20px;
        }
        
        .container {
            background: white;
            border-radius: 20px;
            padding: 40px;
            box-shadow: 0 25px 50px rgba(0,0,0,0.15);
            max-width: 500px;
            width: 100%;
            text-align: center;
        }
        
        h1 {
            color: #333;
            margin-bottom: 20px;
            font-size: 2.5rem;
        }
        
        .warning {
            background: #fff3cd;
            color: #856404;
            border: 1px solid #ffeaa7;
            padding: 20px;
            border-radius: 12px;
            margin-bottom: 30px;
            font-weight: 500;
        }
        
        .btn {
            padding: 15px 30px;
            border: none;
            border-radius: 12px;
            cursor: pointer;
            font-weight: 600;
            font-size: 16px;
            margin: 10px;
            transition: all 0.3s ease;
            display: inline-block;
            text-decoration: none;
        }
        
        .btn-danger {
            background: #dc3545;
            color: white;
        }
        
        .btn-danger:hover {
            background: #c82333;
            transform: translateY(-2px);
        }
        
        .btn-primary {
            background: #007bff;
            color: white;
        }
        
        .btn-primary:hover {
            background: #0056b3;
            transform: translateY(-2px);
        }
        
        .btn-success {
            background: #28a745;
            color: white;
        }
        
        .btn-success:hover {
            background: #218838;
            transform: translateY(-2px);
        }
        
        .message {
            padding: 15px;
            border-radius: 8px;
            margin: 20px 0;
            font-weight: 500;
        }
        
        .message.success {
            background: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }
        
        .message.error {
            background: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }
        
        .stats {
            background: #f8f9fa;
            padding: 20px;
            border-radius: 12px;
            margin: 20px 0;
        }
        
        .stat-item {
            display: flex;
            justify-content: space-between;
            margin: 10px 0;
            padding: 10px;
            background: white;
            border-radius: 8px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>🔄 数据重置</h1>
        
        <div id="message"></div>
        
        <div class="warning">
            ⚠️ <strong>警告：</strong>此操作将清空所有现有数据，包括用户、商家、菜品和订单信息！请确保您已备份重要数据。
        </div>
        
        <div class="stats" id="currentStats">
            <h3>当前数据统计</h3>
            <div id="statsContent">
                <!-- 统计数据将在这里显示 -->
            </div>
        </div>
        
        <button class="btn btn-danger" onclick="resetAllData()">🗑️ 清空所有数据并重新初始化</button>
        <button class="btn btn-primary" onclick="refreshStats()">🔄 刷新统计</button>
        <a href="index.html" class="btn btn-success">🏠 返回首页</a>
    </div>

    <script>
        // 显示消息
        function showMessage(text, type) {
            const messageDiv = document.getElementById('message');
            messageDiv.innerHTML = `<div class="message ${type}">${text}</div>`;
            setTimeout(() => {
                messageDiv.innerHTML = '';
            }, 5000);
        }
        
        // 刷新统计数据
        function refreshStats() {
            const users = JSON.parse(localStorage.getItem('users') || '[]');
            const merchants = JSON.parse(localStorage.getItem('merchants') || '[]');
            const dishes = JSON.parse(localStorage.getItem('dishes') || '[]');
            const orders = JSON.parse(localStorage.getItem('orders') || '[]');
            
            document.getElementById('statsContent').innerHTML = `
                <div class="stat-item">
                    <span>用户数量：</span>
                    <span><strong>${users.length}</strong></span>
                </div>
                <div class="stat-item">
                    <span>商家数量：</span>
                    <span><strong>${merchants.length}</strong></span>
                </div>
                <div class="stat-item">
                    <span>菜品数量：</span>
                    <span><strong>${dishes.length}</strong></span>
                </div>
                <div class="stat-item">
                    <span>订单数量：</span>
                    <span><strong>${orders.length}</strong></span>
                </div>
            `;
        }
        
        // 重置所有数据
        function resetAllData() {
            if (confirm('确定要清空所有数据并重新初始化吗？此操作不可恢复！')) {
                try {
                    // 清空所有localStorage数据
                    localStorage.clear();
                    
                    showMessage('数据已清空！正在重新初始化...', 'success');
                    
                    // 重新加载页面，这会触发数据库重新初始化
                    setTimeout(() => {
                        window.location.reload();
                    }, 1000);
                } catch (error) {
                    showMessage('重置失败：' + error.message, 'error');
                }
            }
        }
        
        // 页面加载时显示统计
        window.onload = function() {
            refreshStats();
        };
    </script>
</body>
</html>
